<template>
  <div class="mod-receiveJobDemo__taskassignment">
    <el-form :inline="true" :model="state.dataForm" @keyup.enter="state.getDataList()">
      <el-input v-model="state.dataForm.wxQqPhone" placeholder="联系方式" clearable
                style="width: 200px;margin-right: 10px"></el-input>
      <el-button @click="state.getDataList()">查询</el-button>
      <el-button v-if="state.hasPermission('receiveJobDemo:taskassignment:save')" type="primary"
                 @click="addOrUpdateHandle()">新增
      </el-button>
      <el-button v-if="state.hasPermission('receiveJobDemo:taskassignment:delete')" type="danger"
                 @click="state.deleteHandle()">删除
      </el-button>
      <el-button v-if="state.hasPermission('receiveJobDemo:taskassignment:export')" type="info"
                 @click="state.exportHandle()">导出
      </el-button>
    </el-form>
    <el-table v-loading="state.dataListLoading" :data="state.dataList" border height="62vh"
              @selection-change="state.dataListSelectionChangeHandle" style="width: 100%;margin-top: 18px">
      <el-table-column type="selection" header-align="center" aligter width="50"></el-table-column>
      <el-table-column prop="content" label="代肝内容" header-align="center" align="center" show-overflow-tooltip
                       width="200"></el-table-column>
      <el-table-column prop="finishTime" label="时效" header-align="center" align="center" width="160"></el-table-column>
      <el-table-column prop="money" label="费用" header-align="center" align="center"></el-table-column>
      <el-table-column prop="assign" label="接单人" header-align="center" align="center"></el-table-column>
      <el-table-column prop="gameUsername" label="游戏账号" header-align="center" align="center"
                       width="150"></el-table-column>
      <el-table-column prop="gamePassword" label="游戏密码" header-align="center" align="center"
                       width="150"></el-table-column>
      <el-table-column prop="gameArea" label="区服" header-align="center" align="center" width="150"></el-table-column>
      <el-table-column prop="wxQqPhone" label="联系方式" header-align="center" align="center" width="120"></el-table-column>
      <el-table-column prop="payMethod" label="支付方式" header-align="center" align="center" width="100"></el-table-column>
      <el-table-column prop="result" fixed="right" label="订单状态" header-align="center" align="center" width="100">
        <template v-slot="scope">
            <el-tag v-if="scope.row.result === '未开打'" type="info">未开打</el-tag>
            <el-tag v-if="scope.row.result === '打单中'" type="primary">打单中</el-tag>
            <el-tag v-if="scope.row.result === '已打完'" type="success">已打完</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="accident" label="意外情况" header-align="center" align="center" width="100"></el-table-column>
      <el-table-column prop="createTime" label="创建时间" header-align="center" align="center"
                       width="160"></el-table-column>
      <el-table-column prop="updateTime" label="更新时间" header-align="center" align="center"
                       width="160"></el-table-column>
      <el-table-column label="操作" fixed="right" header-align="center" align="center" width="170">
        <template v-slot="scope">
          <el-button v-if="state.hasPermission('receiveJobDemo:taskassignment:update')" type="primary" link size="small"
                     @click="addOrUpdateHandle(scope.row.id)">修改
          </el-button>
          <el-button v-if="state.hasPermission('receiveJobDemo:taskassignment:delete')" type="primary" link size="small"
                     @click="state.deleteHandle(scope.row.id)">删除
          </el-button>
          <el-button v-if="scope.row.flag === 0" type="primary" size="small"
                     @click="taskStart(scope.row.id)">开打！
          </el-button>
          <el-button v-if="scope.row.flag === 1" type="danger" size="small"
                     @click="taskEnd(scope.row.id)">结束！
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="state.page" :page-sizes="[10, 20, 50, 100]" :page-size="state.limit"
                   :total="state.total" layout="total, sizes, prev, pager, next, jumper"
                   @size-change="state.pageSizeChangeHandle"
                   @current-change="state.pageCurrentChangeHandle"></el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update ref="addOrUpdateRef" @refreshDataList="state.getDataList">确定</add-or-update>
  </div>
</template>

<script lang="ts" setup>
import useView from "@/hooks/useView";
import {reactive, ref, toRefs} from "vue";
import AddOrUpdate from "./taskassignment-add-or-update.vue";
import baseService from "@/service/baseService";
import {ElMessage} from "element-plus";

const view = reactive({
  deleteIsBatch: true,
  getDataListURL: "/receiveJobDemo/taskassignment/page",
  getDataListIsPage: true,
  exportURL: "/receiveJobDemo/taskassignment/export",
  deleteURL: "/receiveJobDemo/taskassignment",
  dataForm: {
    wxQqPhone: "",
    loginUserType:sessionStorage.getItem("loginUser"),
    loginUsername:sessionStorage.getItem("loginUsername")
  }
});

const state = reactive({...useView(view), ...toRefs(view)});

const emit = defineEmits(["refreshDataList"]);
const addOrUpdateRef = ref();
const addOrUpdateHandle = (id?: number) => {
  addOrUpdateRef.value.init(id);
};

// 订单开打！设置字段
const taskStart = (id?: number) => {
  baseService.get("/receiveJobDemo/taskassignment/taskStart/" + id).then((res) => {
    ElMessage.success({
      message: "开始打单喽！",
      duration: 500,
      onClose: () => {
        state.getDataList()
      }
    })
  });
};
// 订单结束！设置字段
const taskEnd = (id?: number) => {
  baseService.get("/receiveJobDemo/taskassignment/taskEnd/" + id).then((res) => {
    ElMessage.success({
      message: "打完啦！",
      duration: 500,
      onClose: () => {
        state.getDataList()
      }
    })
  });
};
</script>
